# 多无人机种仙人掌


import movement
clear()
def Cacuts(x, y, size):
	def pushdown():
		while True:
			next_dir = None
			x, y = get_pos_x(), get_pos_y()
			self = measure()
			north = measure(North)
			east = measure(East)
			if 0 <= x + movement.direct[East][0] < get_world_size() and 0 <= y + movement.direct[East][1] < get_world_size() and east < self:
				next_dir = East
				self = east
			if 0 <= x + movement.direct[North][0] < get_world_size() and 0 <= y + movement.direct[North][1] < get_world_size() and north < self:
				next_dir = North
				self = north
			if next_dir != None:
				swap(next_dir)
				move(next_dir)
			else:
				break
	
	def need_push_down():
		self = measure()
		while self == None:
			self = measure()
		north = measure(North)
		east = measure(East)
		return (north != None and self > north) or (east != None and self > east)

	for n in range(size * 2 , -1, -1):
		if n % 2 == 0:
			start = 0
			end = size
			step = 1
		else:
			start = size - 1
			end = -1
			step = -1
		for i in range(start, end, step):
			j = n - i
			if j < 0 or j >= size:
				continue
			movement.try_move_to(i, j)
			if get_ground_type() != Grounds.Soil:
				till()
			if get_water() < 0.5:
				use_item(Items.Water)
			plant(Entities.Cactus)
			if need_push_down():
				if i == 0 and j ==0:
					pushdown()
				else:
					while num_drones() >= max_drones():
						do_a_flip()
					spawn_drone(pushdown)
	
	movement.try_move_to(x + size - 1,y + size - 1)
	while num_drones() > 1:
		do_a_flip()
	
	harvest()
while num_items(Items.Cactus) <= 1000000000:
	Cacuts(0, 0, get_world_size())